package com.project.baowei.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


import com.wangshen.base.permission.AddPermission;
import com.project.baowei.bean.request.LoginRequest;
import com.project.baowei.contract.LoginContract;
import com.project.baowei.prsenter.LoginPresenter;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.projectbase.R;

//@Route(path = AppActivityKey.LOGIN)
public class LoginActivity extends BaseMvpActivity<LoginPresenter> implements LoginContract.View {

    EditText etAccount;

    EditText etPassword;

    Button loginBt;

    @Override
    public LoginPresenter getPresenter() {
        return new LoginPresenter();
    }

    @Override
    public int getView() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        etAccount=findViewById(R.id.et_account);
        etPassword=findViewById(R.id.et_password);
        loginBt=findViewById(R.id.login_bt);
        AddPermission addPermission = new AddPermission( this);
        addPermission.addPermission(new AddPermission.PermissionsListener() {
            @Override
            public void onPermissionListener(boolean hasPermission, int code) {
                // checksession();//拿到权限
            }},AddPermission.CODE_PERMISSIONS_LOCATION);
    }

    @Override
    public void initLinsenterner() {
        loginBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onViewClicked();
            }
        });
    }

    @Override
    public void getData() {

    }




    public void onViewClicked() {
        if (TextUtils.isEmpty(etAccount.getText())){
            showMessage("账号不能为空！");
            return;
        }
        if (TextUtils.isEmpty(etPassword.getText())){
            showMessage("密码不能为空！");
            return;
        }
        LoginRequest request=new LoginRequest();
        request.setUsername(etAccount.getText().toString());
        request.setPassword(etPassword.getText().toString());
        presenter.signIn(request);
    }

    @Override
    public void onSuccess() {
        startActivity(new Intent(mContext,HomeActivity.class));
    }
}
